package com.programmercarl.array;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
 *
 * @author yulongtian
 * @create 2024-12-10 13:56
 */
public class Test07 {
    public static void main(String[] args) {
//        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        int[] nums = {1, 1, 2};
        System.out.println(removeDuplicates(nums));
        System.out.println(Arrays.toString(nums));
    }

    public static int removeDuplicates(int[] nums) {
        int slowPointer = 0;
        int fastPointer = 1;
        for (; fastPointer < nums.length; fastPointer++) {
            if (nums[fastPointer] != nums[slowPointer]) {
                nums[++slowPointer] = nums[fastPointer];
            }
        }
        return slowPointer + 1;
    }
}
